package org.itzheng.yuezhi.adapter;

import android.support.v7.widget.RecyclerView;
import android.view.View;
import android.view.ViewGroup;

import org.itzheng.yuezhi.R;
import org.itzheng.yuezhi.adapter.holder.BaseViewHolder;
import org.itzheng.yuezhi.adapter.holder.CommonMenuInfoRcvViewHolder;
import org.itzheng.yuezhi.entity.MenuInfo;
import org.itzheng.yuezhi.utils.comm.UIUtils;

import java.util.List;

/**
 * Created by admin on 2017/7/20.
 */

public class CommonMenuInfoRcvAdapter extends RecyclerView.Adapter<BaseViewHolder> {
    private List<MenuInfo> mItems;

    public CommonMenuInfoRcvAdapter(List<MenuInfo> menuInfos) {
        mItems = menuInfos;
    }

    @Override
    public BaseViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = UIUtils.inflate(R.layout.adapter_common_menu_info);
        return new CommonMenuInfoRcvViewHolder(view).bindButterKnife();
    }

    @Override
    public void onBindViewHolder(BaseViewHolder holder, int position) {
        if (holder instanceof CommonMenuInfoRcvViewHolder) {
            CommonMenuInfoRcvViewHolder viewHolder = (CommonMenuInfoRcvViewHolder) holder;
            MenuInfo menuInfo = mItems.get(position);
            viewHolder.tvTitle.setText(menuInfo.title);
            viewHolder.itemView.setOnClickListener(menuInfo.onClickListener);
        }

    }

    @Override
    public int getItemCount() {
        return mItems == null ? 0 : mItems.size();
    }
}
